global !p

from mdtex.scopes import math, display_math, inline_math, chem, not_chem, unit, not_unit

endglobal

################################################################
#                                                              #
#                         Environments                         #
#                                                              #
################################################################

context "inline_math()"
snippet env "环境 Environment" w
\begin{${1:environment}} ${2:${VISUAL}} \end{$1}$0
endsnippet

context "display_math()"
snippet env "环境 Environment" w
\begin{${1:environment}}
    ${2:${VISUAL}}
\end{$1}$0
endsnippet

context "inline_math()"
snippet envo "环境（选项） Environment(option)" w
\begin{${1:environment}}{${2:option}} ${3:${VISUAL}} \end{$1}$0
endsnippet

context "display_math()"
snippet envo "环境（选项） Environment(option)" w
\begin{${1:environment}}{${2:option}}
    ${3:${VISUAL}}
\end{$1}$0
endsnippet

context "inline_math()"
snippet case "方程组" w
\left\lbrace\begin{aligned} ${1:${VISUAL}} \end{aligned}\right.$0
endsnippet

context "display_math()"
snippet case "方程组" w
\left\lbrace\begin{aligned}
    ${1:${VISUAL}}
\end{aligned}\right.$0
endsnippet

context "inline_math()"
snippet cases "Cases 环境 Cases Environment" w
\begin{cases} ${1:${VISUAL}} \end{cases}$0
endsnippet

context "display_math()"
snippet cases "Cases 环境 Cases Environment" w
\begin{cases}
    ${1:${VISUAL}}
\end{cases}$0
endsnippet

context "inline_math()"
snippet align "Aligned 环境 Aligned Environment" w
\begin{aligned} ${1:${VISUAL}} \end{aligned}$0
endsnippet

context "display_math()"
snippet align "Aligned 环境 Aligned Environment" w
\begin{aligned}
    ${1:${VISUAL}}
\end{aligned}$0
endsnippet

context "math()"
snippet "\\?\bte?xt" "文本环境 Text Environment" r
\text{$1}$0
endsnippet

context "math()"
snippet "\\?\btt" "文本环境 Text Environment" r
\text{$1}$0
endsnippet

context "math() and not_chem()"
snippet "\\?\bce" "化学环境 Chemistry Environment" r
\ce{$1}$0
endsnippet

context "math() and not_unit()"
snippet "\\?\bpu" "单位环境 Unit Environment" r
\pu{$1}$0
endsnippet

context "math()"
snippet "\\?\btag" "标记 Tag" r
\tag{$1}$0
endsnippet

context "math() and not_chem()"
snippet = "环境等号 Environment Equal" i
&=
endsnippet

priority 1
context "math()"
snippet &= "环境等号 Environment Equal" i
=
endsnippet
